<?php use_helper('I18N', 'Date') ?>
<?php use_stylesheet('/sf/sf_admin/css/main') ?>
<?php include_partial('ringtone/submenu', array('nhac' => 'rt_approve_comment','type'=>'extend')) ?>
<div id="sf_admin_container">
<?php echo form_tag('ringtone_xml/reorder', array(
  'id'        => 'formblog',
  'name'      => 'formblog',
  'multipart' => true,
  'onsubmit'  =>'return checkvalue()',
)) ?>

<h1><?php echo __('Tạo file XML cho danh sách bài hot', 
array()) ?></h1>
<div id="success" style="display: none;width: 100%; height: 20px;background: #366388;overflow: hidden;"></div>
<br clear="all" />
<div style="float: right;width: 70%">
        Số ringtone hiện thị:    <input type="text" id ="numRt" name="numRt" value="4"style="width: 20px;" />
        <div style="float: right">
	<input type="submit" name="reorder" value="Sắp xếp lại" onclick="reorder()" />
	&nbsp;
	<input type="button" name="createfile" value="Tạo XML" onclick="createxml()" />
        </div>
        
</div>
<br clear="all" />
	<div class="xml-col1">
		<fieldset>
			<legend>Chọn bài mới</legend>
			<input type="text" name="ringname" id="ringname" value="" />
			<input type="button" name="search" value="Tìm" onclick="showresult(document.getElementById('ringname').value)">
			<div id="result">
			
			</div>
		</fieldset>
		
	</div>
	<div class="xml-col2" id ="sf_admin_content">
		<fieldset>
		<legend>Danh sách mặc định 20 bài top download</legend>
		<table width="100%" cellpadding="0" cellspacing="0" class="sf_admin_list">
			<tr>
				<th>ID</th>
				<th>Tên bài</th>
				<th>Thể hiện</th>
				<th>Chi tiết</th>
				<th width="15">Sắp xếp</th>
				<th>Background</th>
				<th>Xóa</th>
			</tr>
			<?php $i=0; foreach($listxml as $item){?>
			<tr class="sf_admin_row_<?php echo $i%2 ?>">
				<td><?php echo $item->getRingtoneid()?></td>
				<td><?php echo $item->getName()?></td>
				<td><?php  echo $item->getSinger()?></td>
				<td><a href="<?php echo $item->getUrl()?>" target="_blank">Xem</a> </td>
				<td><input type="text" name="order[<?php echo $item->getRingtoneid()?>]" value="<?php echo $item->getordering()?>" style="width: 20px"> </td>
				<td>
				<a class="thickbox" href="<?php echo url_for('ringtone_xml/upload?id=' . $item->getRingtoneid())?>?keepThis=true&TB_iframe=true&height=300&width=350" title="Upload ảnh">
					<?php 
						if($item->getBackground())
							echo 'Thay ảnh khác';
						else
							echo 'Upload mới'
					?>
				</a>
				</td>
				<td><a href="javascript:delrecord('<?php echo $item->getRingtoneid()?>')">Xóa</a></td>
			</tr>
			<?php $i++;}?>
		</table>
		</fieldset>
	</div>
</div>


<script type="text/javascript">
function showresult(val){
	$.ajax({		
		  url: '/ringtone_xml/search?name='+val,
		  success: function(data) {
		    $('#result').html(data);
		  }
		});
}

function add2list(val){
	$.ajax({		
		  url: '/ringtone_xml/add2list?id='+val,
		  success: function(data) {
		    $('#sf_admin_content').html(data);
		    $("#success").html('Đã thêm mới').hide().fadeIn(2000);
		    setTimeout(function(){
		    	$("#success").fadeOut(2000);
			    })

		  }
		});
}

function delrecord(val){
	if(confirm('Bạn có chắc chắn xóa?')){
		$.ajax({		
			  url: '/ringtone_xml/delrecord?id='+val,
			  success: function(data) {
			    $('#sf_admin_content').html(data);
			    $("#success").html('Đã xóa khỏi danh sách').hide().fadeIn(2000);
			    setTimeout(function(){
			    	$("#success").fadeOut(2000);
				    })
	
			  }
			});
	}
}

function createxml(){
        var num = document.getElementById('numRt').value;
        if (num > 0 && num <=20){
            $.ajax({
		  url: '/ringtone_xml/savefile?numRt='+num,
		  success: function(data) {
		    $('#sf_admin_content').html(data);
		    $("#success").html('Đã tạo file XML').hide().fadeIn(2000);
		    setTimeout(function(){
		    	$("#success").fadeOut(2000);
			    })

		  }
		});
        }else{
            alert('Số Ringtone phải trong khoản 1 - 20');
        }
	
}
</script>
</form>